package com.nervenets.web.redis.domain.user;


import com.nervenets.web.enumeration.Gender;
import com.nervenets.web.hibernate.domain.user.User;
import com.nervenets.web.hibernate.domain.user.UserInfo;
import com.nervenets.web.hibernate.domain.user.UserRole;
import com.nervenets.web.redis.RedisSetDomain;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 记录单个用户信息
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class UserStored extends RedisSetDomain {
    private long userId;
    private String mobile;
    private UserRole role;
    private int createTime;
    private String wechatId;
    private String unionId;
    private String name;
    private String avatar;
    private Gender gender;
    private int birthday;
    private int areaId;
    private UserInfo info;

    @Override
    public String getField() {
        return String.valueOf(userId);
    }

    @Override
    public String getKey() {
        return String.format("U_V1_%s", String.format("%04d", userId).substring(0, 4));
    }

    public UserStored() {
    }

    public UserStored(long userId) {
        this.userId = userId;
    }

    public UserStored(User user) {
        this.userId = user.getId();
        this.mobile = user.getMobile();
        this.role = user.getRole();
        this.createTime = user.getCreateTime();
        this.wechatId = user.getWechatId();
        this.unionId = user.getUnionId();
        this.name = user.getInfo().getName();
        this.avatar = user.getAvatar();
        this.gender = user.getGender();
        this.birthday = user.getBirthday();
        this.areaId = user.getAreaId();
        this.info = user.getInfo();
    }

}
